package com.lluohao.common;

import com.lluohao.web.controller.MessageVO;
import com.lluohao.web.controller.Result;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Everthing-- on 2017/7/5.
 */
public class RecordMessageHandler implements MessageHandler {
    private Map<String, String> ques = new HashMap<String, String>();
    public Result handler(MessageVO message) {
        String content = message.getMsg();
        if(support(content)){
            content = content.replace("记住", "");
            String[] arr = content.split("=");
            ques.put(arr[0], arr[1]);
            Result result = new Result();
            result.setMessage("记住了");
            if(StringUtils.notNull(message.getGroupNum())){
                result.setAt(message.getQq());
            }
            return result;
        }
        if(ques.get(message.getMsg())!=null){
            Result result = new Result();
            result.setMessage(ques.get(message.getMsg()));
            if(StringUtils.notNull(message.getGroupNum())){
                result.setAt(message.getQq());
            }
            return result;
        }
        return null;
    }

    public boolean support(String str){
        if(!StringUtils.notNull(str)){
            return false;
        }
        if(str.startsWith("记住")&&str.contains("=")){
            return true;
        }
        return false;
    }
}
